gdk/wayland: Add GdkDisplay call to query available globals
authorCarlos Garnacho <carlosg@gnome.org>
Tue, 13 Feb 2018 13:28:44 +0000 (14:28 +0100)
committerCarlos Garnacho <carlosg@gnome.org>
Wed, 14 Feb 2018 13:58:06 +0000 (14:58 +0100)
The internal known_globals hashtable is used to carry accounting for
interfaces that depend on others (as ordering is not guaranteed), extend
its usage so it also keeps track of unimplemented interfaces (here at
least).

The API call will then use this to allow querying the globals offered by
the compositor, it will be useful to determine whether we can use
text-input protocols or should fallback to other IMs.

docs/reference/gdk/gdk3-sections.txt
gdk/wayland/gdkdisplay-wayland.c
gdk/wayland/gdkwaylanddisplay.h

index f26c22d3c6d667cc440738a5999b680e90e95fa3..4e5c403670358d52e986e28bc9ef47f7792e92fb 100644 (file)
@@ -1270,6 +1270,7 @@ gdk_wayland_device_get_wl_seat
 gdk_wayland_display_get_wl_compositor
 gdk_wayland_display_get_wl_display
 gdk_wayland_display_get_xdg_shell
+gdk_wayland_display_query_registry
 gdk_wayland_window_get_wl_surface
 gdk_wayland_window_set_use_custom_surface
 GdkWaylandWindowExported
index 8bcd6755a618c51d3784fd32c28dbc1e8cc464ea..3e9ca8465d7c59568bfdf41243de93b4a62ce229 100644 (file)
@@ -372,7 +372,6 @@ gdk_registry_handle_global (void               *data,
 {
   GdkWaylandDisplay *display_wayland = data;
   struct wl_output *output;
-  gboolean handled = TRUE;
 
   GDK_NOTE (MISC,
             g_message ("add global %u, interface %s, version %u", id, interface, version));
@@ -495,12 +494,9 @@ gdk_registry_handle_global (void               *data,
                                                            &server_decoration_listener,
                                                            display_wayland);
     }
-  else
-    handled = FALSE;
 
-  if (handled)
-    g_hash_table_insert (display_wayland->known_globals,
-                         GUINT_TO_POINTER (id), g_strdup (interface));
+  g_hash_table_insert (display_wayland->known_globals,
+                       GUINT_TO_POINTER (id), g_strdup (interface));
 
   process_on_globals_closures (display_wayland);
 }
@@ -1386,3 +1382,37 @@ gdk_wayland_display_get_selection (GdkDisplay *display)
 
   return display_wayland->selection;
 }
+
+/**
+ * gdk_wayland_display_query_registry:
+ * @display: a wayland #GdkDisplay
+ * @interface: global interface to query in the registry
+ *
+ * Returns %TRUE if the the interface was found in the display
+ * wl_registry.global handler.
+ *
+ * Returns: %TRUE if the global is offered by the compositor
+ *
+ * Since: 3.22.27
+ **/
+gboolean
+gdk_wayland_display_query_registry (GdkDisplay  *display,
+                                   const gchar *global)
+{
+  GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display);
+  GHashTableIter iter;
+  gchar *value;
+
+  g_return_val_if_fail (GDK_IS_WAYLAND_DISPLAY (display), FALSE);
+  g_return_val_if_fail (global != NULL, FALSE);
+
+  g_hash_table_iter_init (&iter, display_wayland->known_globals);
+
+  while (g_hash_table_iter_next (&iter, NULL, (gpointer*) &value))
+    {
+      if (strcmp (value, global) == 0)
+        return TRUE;
+    }
+
+  return FALSE;
+}
index d980d6cf87864af12271957f1cce5127a841151c..af9cc896be095c7200b89b91aa6f67062a036cdb 100644 (file)
@@ -60,6 +60,10 @@ void                    gdk_wayland_display_set_startup_notification_id (GdkDisp
 GDK_AVAILABLE_IN_3_22
 gboolean                gdk_wayland_display_prefers_ssd         (GdkDisplay *display);
 
+GDK_AVAILABLE_IN_3_22
+gboolean                gdk_wayland_display_query_registry      (GdkDisplay  *display,
+                                                                const gchar *global);
+
 G_END_DECLS
 
 #endif /* __GDK_WAYLAND_DISPLAY_H__ */